/*
# $Id$
*/

/*
# @function void selectFile( string file )
# file	= File to open
#
# Opens the file, or sends it back to the tinymce element that opened this
# interface.
*/
function selectFile(file) {

	// Send chosen file back to opener
	if(tinyMCEPopup) {
		var opener = tinyMCEPopup.getWindowArg('window');
		var src = opener.document.getElementById('src');
		src.value = file.href;
		opener.ImageDialog.showPreviewImage(src.value);
		var desc = opener.document.getElementById('alt');
		desc.value = file.lastChild.nodeValue;
		self.close();
		return false;
	}
	return true;
}

/*
# @function void deleteItem( string file )
# file	= File to delete
#
*/
var dItem = null;
function deleteItem(file, el) {
	if(!confirm("Are you sure you want to remove this item?")) {
		return false;
	}

	dItem = el;
	$.post('/scribble/media-library', {
		method: 'delete',
		df: file
	}, doDeleteItem);
	return false;
}

function doDeleteItem(r) {
	if(r!='OK') {
		alert(r);
	}
	else {
		$(dItem).parents('tr').remove();
	}
	dItem = null;
}